package com.mbc.mapper;


import com.mbc.vo.MbcBlackListInfoAndMbcBlackListVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 黑名单表 Mapper 接口
 * </p>
 *
 * @author suimeng
 * @date 2024/04/15
 * @since 2024-04-15
 */

@Mapper
public interface BlackListMapper {
    /**
     * 插入黑名单用户
     *
     * @param userId              用户 ID
     * @param reasonsId           被举报人 ID
     * @param reasonsForReporting 举报理由
     * @param name                名字
     * @param wechatNumber        微信号
     * @param phoneNumber         电话号码
     * @param now                 举报时间
     * @return int
     */
    @Insert("insert into mbc_black_list(user_id, reasons_id, reasons_for_reporting, report_url, Wechat_number, " +
            "phone_number, reporting_time, name)" +
            " values (#{userId},#{reasonsId},#{reasonsForReporting},#{reportUrl},#{wechatNumber}," +
            "#{phoneNumber},#{now},#{name})")
    int insertBlackUser(Integer userId, Integer reasonsId, String reasonsForReporting, String reportUrl, String name,
                        String wechatNumber, String phoneNumber, LocalDateTime now);


    /**
     * 根据用户id获取被举报人id
     *
     * @param userId 用户 ID
     * @return {@link Integer}
     */
    @Select("select reasons_id from mbc_black_list where user_id = #{userId}")
    Integer getByUserId(Integer userId);

    /**
     * 分页查询全部黑名单用户
     *
     * @return {@link List}<{@link MbcBlackListInfoAndMbcBlackListVO}>
     */
    /*@Select("select mbc_black_list.*, mbc_black_list_info.* from mbc_black_list inner join mbc_black_list_info on " +
            "mbc_black_list.reasons_id = mbc_black_list_info.user_id")*/
    @Select("select mbc_black_list.*, a.user_id,a.sex,a.name name2,a.nickname,a.wechat_number wechatNumber2, a" +
            ".phone_number phoneNumber2 , a.city,a.address from mbc_black_list inner join mbc_black_list_info a on " +
            "mbc_black_list.reasons_id = a.user_id order by mbc_black_list.reporting_time")
    List<MbcBlackListInfoAndMbcBlackListVO> getByBlackUser();

    /**
     * 条件查询根据被举报人id查询全部黑名单信息
     *
     * @param userId 用户 ID
     * @param offset 抵消
     * @param limit  限制
     * @return {@link ArrayList}<{@link MbcBlackListInfoAndMbcBlackListVO}>
     */
    @Select("select mbc_black_list.*, a.user_id,a.sex,a.name name2,a.nickname,a.wechat_number wechatNumber2, a" +
            ".phone_number phoneNumber2 , a.city,a.address from mbc_black_list inner join mbc_black_list_info a  on " +
            "mbc_black_list.reasons_id = a.user_id where a.user_id = #{userId} order by mbc_black_list.reporting_time" +
            " limit #{offset},#{limit}")
    ArrayList<MbcBlackListInfoAndMbcBlackListVO> getByConditionUserIdBlackUser(Integer userId, Integer offset,
                                                                               Integer limit);

    /**
     * 条件查询根据被举报人姓名查询全部黑名单信息
     *
     * @param name   名字
     * @param offset 抵消
     * @param limit  限制
     * @return {@link ArrayList}<{@link MbcBlackListInfoAndMbcBlackListVO}>
     */
    @Select("select mbc_black_list.*, a.user_id,a.sex,a.name name2,a.nickname,a.wechat_number wechatNumber2, a" +
            ".phone_number phoneNumber2 , a.city,a.address from mbc_black_list inner join mbc_black_list_info a  on " +
            "mbc_black_list.reasons_id = a.user_id where a.name = #{name} order by mbc_black_list.reporting_time " +
            "limit #{offset},#{limit}")
    ArrayList<MbcBlackListInfoAndMbcBlackListVO> getByConditionNameBlackUser(String name, Integer offset,
                                                                             Integer limit);

    /**
     * 条件查询根据被举报人nickname查询全部黑名单信息
     *
     * @param nickname 昵称
     * @param offset   抵消
     * @param limit    限制
     * @return {@link ArrayList}<{@link MbcBlackListInfoAndMbcBlackListVO}>
     */
    @Select("select mbc_black_list.*, a.user_id,a.sex,a.name name2,a.nickname,a.wechat_number wechatNumber2, a" +
            ".phone_number phoneNumber2 , a.city,a.address from mbc_black_list inner join mbc_black_list_info a  on " +
            "mbc_black_list.reasons_id = a.user_id where a.nickname = #{nickname} order by mbc_black_list" +
            ".reporting_time limit #{offset},#{limit}")
    ArrayList<MbcBlackListInfoAndMbcBlackListVO> getByConditionNickNameBlackUser(String nickname, Integer offset,
                                                                                 Integer limit);

    /**
     * 更新黑名单信息
     *
     * @param reasonsForReporting 举报理由
     * @param reportUrl           报告网址
     * @param wechatNumber        微信号
     * @param phoneNumber         电话号码
     * @param now                 现在
     * @param name                名字
     * @return int
     */
    @Update("update mbc_black_list set reasons_for_reporting = #{reasonsForReporting},report_url = #{reportUrl}," +
            "Wechat_number = #{wechatNumber} ,phone_number = #{phoneNumber},reporting_time = #{now},name = #{name} " +
            "where user_id = #{userId}")
    int updateBlackUser(Integer userId, String reasonsForReporting, String reportUrl, String wechatNumber,
                        String phoneNumber,
                        LocalDateTime now, String name);
}
